(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/Hit.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '2a857HXT7FGMqsl+uor4ApL', 'Hit', __filename);
// Script/Hit.js

"use strict";

// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
var Game = require("Game");
var BlockInputs = require("BlockInputs");
var AU = require("AudioUtils");
cc.Class({
	extends: cc.Component,

	properties: {
		// foo: {
		//     // ATTRIBUTES:
		//     default: null,        // The default value will be used only when the component attaching
		//                           // to a node for the first time
		//     type: cc.SpriteFrame, // optional, default is typeof default
		//     serializable: true,   // optional, default is true
		// },
		// bar: {
		//     get () {
		//         return this._bar;
		//     },
		//     set (value) {
		//         this._bar = value;
		//     }
		// },
	},

	onCollisionEnter: function onCollisionEnter(other, self) {
		//碰撞则播放爆炸动画
		//子弹
		if (self.node.group == 'bullet') {
			//			console.log(self.getComponent("Bullet").isGood);
			var isGood = self.getComponent("Bullet").isGood;
			if (isGood == 0) {
				//我方子弹
				if (other.node.group == 'enemy') {
					//敌机
					//子弹碰撞飞机后,飞机生命值-子弹威力值,再更新progressbar的状态
					var powerNum = self.node.getComponent("Bullet").powerNum; //子弹威力
					var bloodNum = other.node.getComponent("BadFly").bloodNum;
					var isDie = other.node.getComponent("BadFly")._updateProgressBar(powerNum);
					if (isDie) {
						AU.inst.playEffect(EFFECT_BOOM1, false);
						other.node.group = 'default';
						self.node.group = 'default';
						//cc.find("bg/lab",item)
						var anmi = other.node.getComponent(cc.Animation);
						anmi.play("boom"); //播放动画
						//爆炸产生金币
						Game.inst.createNewGolden(100, 3, other.node.x, other.node.y);
						self.node.destroy();
						//other.node.removeFromParent(); 
						/*anmi.on('finished',function(e){
      	self.node.removeFromParent();
          	//other.node.removeFromParent(); 
      },self);*/
						anmi.on('finished', function (e) {
							other.node.destroy(); //必须动画播放完成后再remove改节点,因为animation是从改对象上获取的
						}, other);
					} else {
						self.node.destroy();
						self.node.group = 'default';
					}
				}
			} else if (isGood == 1) {
				//敌方子弹
				if (other.node.group == 'hero') {
					AU.inst.playEffect(EFFECT_BOOM1, false);
					//弹出继续 /重新开始界面
					//结束游戏界面隐藏
					var blockInputs = cc.find('Canvas/blockInputs');
					blockInputs.active = true;
					blockInputs.getChildByName('btn_goOnPlay').active = true;
					blockInputs.getChildByName('btn_reStart').active = true;
					blockInputs.getChildByName('btn_back2Home').active = true;
					AU.inst.setStopEffect(EFFECT_BULLET_SHOT1);
					//BlockInputs.node.active = true;

					self.node.group = 'default';
					self.node.destroy();
					cc.director.pause(); //暂停

					/*self.node.group = 'default';
     other.node.group = 'default';
     var anmi = other.node.getComponent(cc.Animation);
                 anmi.play("boom"); //播放动画
                 self.node.destroy();
                 anmi.on('finished',function(e){
                 	cc.director.pause();//暂停
                 	//this.node.cleanup();
                 	//other.node.destroy();//必须动画播放完成后再remove改节点,因为animation是从改对象上获取的
                 },other); */
				} else if (other.node.group == 'jineng') {
					//敌机子弹碰撞技能1
					self.node.destroy();
				}
			}
		} else if (self.node.group == 'hero') {
			if (other.node.group == 'enemy') {
				AU.inst.playEffect(EFFECT_BOOM1, false);
				var blockInputs = cc.find('Canvas/blockInputs'); //hero死亡要动态显示按钮
				blockInputs.active = true;
				blockInputs.getChildByName('btn_goOnPlay').active = true;
				blockInputs.getChildByName('btn_reStart').active = true;
				blockInputs.getChildByName('btn_back2Home').active = true;
				AU.inst.setStopEffect(EFFECT_BULLET_SHOT1);
				//BlockInputs.node.active = true;

				other.node.group = 'default';
				other.node.destroy();
				cc.director.pause(); //暂停

				/*var anmi = self.node.getComponent(cc.Animation);
                anmi.play("boom"); //播放动画
                anmi.on('finished',function(e){
                		self.node.destroy();
                       // var score = this.node.getComponent(cc.Label);   
                },self); */
				//self.node.removeFromParent();
			}
		} else if (self.node.group == 'enemy') {
			/*if(other.node.group == 'enemy'){
   	other.node.removeFromParent();
   }*/
		} else if (self.node.group == 'prop') {
			AU.inst.playEffect(EFFECT_DUDUDU, false);
			wx.vibrateShort();
			var propType = self.getComponent("PropIcon").propType;
			if (propType == 0) {
				//jineng1icon
				if (other.node.group == 'hero') {
					//英雄吃到道具
					self.node.group = 'default';
					self.node.destroy();
					//var anmi = other.node.getComponent(cc.Animation);
					//anmi.play("jineng1"); //播放动画
					Game.inst.createJinengAnim();
				}
			} else if (propType == 1) {
				//protect1icon
				if (other.node.group == 'hero') {
					//英雄吃到道具
					self.node.group = 'default';
					self.node.destroy();
					//var anmi = other.node.getComponent(cc.Animation);
					//anmi.play("jineng1"); //播放动画
					Game.inst.showProtect1(); //显示护盾
				}
			}
		} else if (self.node.group == 'jineng') {
			if (other.node.group == 'enemy') {
				//敌机撞到技能
				AU.inst.playEffect(EFFECT_BOOM1, false);
				other.node.group = 'default';
				Game.inst.createNewGolden(100, 5, other.node.x, other.node.y);
				var anmi = other.node.getComponent(cc.Animation);
				anmi.play("boom"); //播放动画
				anmi.on('finished', function (e) {
					other.node.destroy();
				}, other);
			}
		}
	},

	// onLoad () {},

	start: function start() {}
}

// update (dt) {},
);

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=Hit.js.map
        